using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Administrator
{
	public partial class ucSession : UserControl
	{
        private bool LoadSetting = false;
        private DigitTextBox dtbTimeOut;

		public ucSession()
		{
			InitializeComponent();
            Init();
            
		}

        private void Init()
        {
            this.dtbTimeOut = new DigitTextBox();
            
            // 
            // dtbTimeOut 
            // 
            this.dtbTimeOut.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
             | System.Windows.Forms.AnchorStyles.Right)));
            this.dtbTimeOut.Font = new System.Drawing.Font("Tahoma", 8.25F);
            this.dtbTimeOut.Location = new System.Drawing.Point(2, 104);
            this.dtbTimeOut.MaxLength = 8;
            this.dtbTimeOut.Name = "dtbTimeOut";
            this.dtbTimeOut.Size = new System.Drawing.Size(585, 21);
            this.dtbTimeOut.TabIndex = 7;
            this.dtbTimeOut.TextChanged += new System.EventHandler(this.tbTimeOut_TextChanged);
            this.dtbTimeOut.Leave += new System.EventHandler(this.tbTimeOut_Leave);
            this.dtbTimeOut.KeyUp += new System.Windows.Forms.KeyEventHandler(this.tbTimeOut_KeyUp);
            this.dtbTimeOut.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbTimeOut_KeyPress);
            this.Controls.Add(this.dtbTimeOut);
        }

		public void FillFields(Byte FillType)
		{
			LoadSetting = true;
            
            lbUserName.Text = cConst.USER_NAME_CAP;
            lbPassword.Text = cConst.USER_PASS_CAP;
            lbTimeOut.Text = cConst.SESS_TIMEOUT_CAP;
            lbUseSessionParam.Text = cConst.NETWORK_DEVICE_SESSION_USE_CAP;
            
            //tbUserName.Text = cMain.SessionParam.UserName;
            //tbPassword.Text = cMain.SessionParam.UserPass;
            //dtbTimeOut.Text = cMain.SessionParam.TimeOut.ToString();
            lbUseSessionParam.Visible = false;

            //if ((FillType != cConst.FILL_TASK_ACTION) &&
            //    (cGroup.ActiveModule.ObjectIndex >= 0) &&
            //    (cGroup.ActiveModule.DeviceIndex >= 0))
            //{
            //    if (cGroup.Network.Objects[cGroup.ActiveModule.ObjectIndex].Devices[cGroup.ActiveModule.DeviceIndex].UseSessionParam)
            //    {
            //        tbUserName.Text = cGroup.Network.Objects[cGroup.ActiveModule.ObjectIndex].Devices[cGroup.ActiveModule.DeviceIndex].UserName;
            //        tbPassword.Text = cGroup.Network.Objects[cGroup.ActiveModule.ObjectIndex].Devices[cGroup.ActiveModule.DeviceIndex].UserPass;
            //        dtbTimeOut.Text = cGroup.Network.Objects[cGroup.ActiveModule.ObjectIndex].Devices[cGroup.ActiveModule.DeviceIndex].SessionTimeOut.ToString(); 
            //        lbUseSessionParam.Visible = true;
            //        tbUserName.Enabled = false;
            //        tbPassword.Enabled = false;
            //        dtbTimeOut.Enabled = false;
            //    }
            //    else
            //    {
            //        tbUserName.Enabled = true;
            //        tbPassword.Enabled = true;
            //        dtbTimeOut.Enabled = true;
            //    }
            //}            
			LoadSetting = false;	
		}
		private void tbUserName_TextChanged(object sender, EventArgs e)
		{
            //if (!LoadSetting) cMain.SessionParam.UserName = tbUserName.Text;
		}
		private void tbPassword_TextChanged(object sender, EventArgs e)
		{
            //if (!LoadSetting) cMain.SessionParam.UserPass = tbPassword.Text;
		}
		private void tbTimeOut_KeyPress(object sender, KeyPressEventArgs e)
		{

		}
        private void tbTimeOut_KeyUp(object sender, KeyEventArgs e)
        {
            
        }
		private void tbTimeOut_TextChanged(object sender, EventArgs e)
		{
			if (!LoadSetting)
			{
				if (((TextBox)sender).Text != "")
				{
                    if (Int32.Parse(((TextBox)sender).Text) > 99999999) ((TextBox)sender).Text = "99999999";
                    //if (sender == dtbTimeOut) cMain.SessionParam.TimeOut = UInt32.Parse(((TextBox)sender).Text);                    
				}
			}
		}
        private void tbTimeOut_Leave(object sender, EventArgs e)
        {
            //if (((TextBox)sender).Text == "") ((TextBox)sender).Text = cMain.SessionParam.TimeOut.ToString();
        }

       

        
        

      

       

	}
}
